package com.data.collect.tool.cach;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * @author linxi
 * @since preferce管理类  这个是个单利类 可压抑用系统的路径 data/下的SYSTEM_CACHE 配置文件 也可以继续拧自己简历配置文件
 */
public class PreferceManager {

    private static PreferceManager instance;
    private String SYSTEM_CACHE = "SDK_SYSTEM_CACHE";
    private PreferceManager() {
    }
    public static PreferceManager getInsance() {
        if (instance == null) {
            instance = new PreferceManager();
        }
        return instance;
    }
    /**
     * 用sdk的缓存路径  SYSTEM_CACHE 文件中
     *
     * @param value   需要储存的value
     * @param key     需要 储存的key
     */
    public void saveValueBYkey(String key, String value, Context context) {
        SharedPreferences preferences = context.getSharedPreferences(
                SYSTEM_CACHE, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putString(key, value);
        editor.commit();
    }
    /**
     * 用sdk的缓存路径  SYSTEM_CACHE 文件中
     *
     * @param value   需要储存的value
     * @param key     需要 储存的key
     */
    public void saveIntegerValueBYkey(String key, int
            value, Context context) {
        SharedPreferences preferences = context.getSharedPreferences(
                SYSTEM_CACHE, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putInt(key, value);
        editor.commit();
    }
    /**
     * 取值 SYSTEM_CACHE  中的value
     *
     * @param key
     * @return value
     */
    public String getValueBYkey(String key, Context context) {
        SharedPreferences preferences = context.getSharedPreferences(
                SYSTEM_CACHE, Context.MODE_PRIVATE);
        String value = preferences.getString(key, "");
        return value;
    }

    /**
     * 取值 SYSTEM_CACHE  中的value
     *
     * @param key
     * @return value
     */
    public int getIntegerValueBYkey(String key, Context context) {
        SharedPreferences preferences = context.getSharedPreferences(
                SYSTEM_CACHE, Context.MODE_PRIVATE);
        int value = preferences.getInt(key, 0);
        return value;
    }


}
